﻿Public Class frmStudentControl

    Private Sub frmStudentControl_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Connect()

        Me.WindowState = FormWindowState.Maximized
        txtStudentID.Text = AutoID4Access("SELECT StudentID FROM tbl_students", "tbl_students") + 1


    End Sub

    Private Sub BtnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
        Try
            If Me.txtStudentID.Text = "" Then
                MsgBox("Please Input Value !", MsgBoxStyle.Exclamation)
                Me.txtStudentID.Focus()
            ElseIf Me.txtFName.Text = "" Then
                MsgBox("Please Input Value !", MsgBoxStyle.Exclamation)
                Me.txtFName.Focus()
            ElseIf Me.txtLName.Text = "" Then
                MsgBox("Please Input Value !", MsgBoxStyle.Exclamation)
                txtLName.Focus()
            ElseIf txtLFName.Text = "" Then
                MsgBox("Please Input Value !", MsgBoxStyle.Exclamation)
                txtLFName.Focus()
            ElseIf txtLLName.Text = "" Then
                MsgBox("Please Input Value !", MsgBoxStyle.Exclamation)
                txtLLName.Focus()
            ElseIf cboSex.Text = "" Then
                MsgBox("Please Input Value !", MsgBoxStyle.Exclamation)
                cboSex.Focus()
            ElseIf txtDOB.Text = "" Then
                MsgBox("Please Input Value !", MsgBoxStyle.Exclamation)
                txtDOB.Focus()
            ElseIf txtPOB.Text = "" Then
                MsgBox("Please Input Value !", MsgBoxStyle.Exclamation)
                txtPOB.Focus()
            Else
                txtStudentID.Text = AutoID4Access("SELECT StudentID FROM tbl_students", "tbl_students") + 1
                Dim SQL As String
                SQL = "INSERT INTO tbl_students (StudentID,FName,LName,LFName,LLName,Gender,DOB,POB,Notes) VALUES(" & _
                txtStudentID.Text & ",'" & txtFName.Text & "','" & txtLName.Text & "','" & txtLFName.Text & "','" & txtLLName.Text & "','" & cboSex.Text & "','" & txtDOB.Text & "','" & txtPOB.Text & "','" & txtNote.Text & "')"
                SaveDataToAccess(SQL)

                MsgBox(" Save Success!", MsgBoxStyle.Information)
            End If
        Catch ex As Exception
            'MsgBox(ex)

        End Try
    End Sub
End Class